;
; Copyright (c) Microsoft Corporation.  All rights reserved.
;
;
; Use of this sample source code is subject to the terms of the Microsoft
; license agreement under which you licensed this sample source code. If
; you did not accept the terms of the license agreement, you are not
; authorized to use this sample source code. For the terms of the license,
; please see the license agreement between you and Microsoft or, if applicable,
; see the LICENSE.RTF on your install media or the root of your tools installation.
; THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
;
;
; (C) Copyright 2006 Marvell International Ltd.
; All Rights Reserved
;
; Copyright (c) 1998, 1999 ARM Limited
; All Rights Reserved
;


    OPT     2       ; disable listing
    INCLUDE kxarm.h
    OPT     1       ; reenable listing
    OPT     128     ; disable listing of macro expansions
    INCLUDE armmacros.s


    TEXTAREA

    LEAF_ENTRY	XScaleFlushDCacheLinesL2
;++
; Routine Description:
;    Clean and invalidate some number of Data Cache lines.
;
; Syntax:
;	void XScaleFlushDCacheLines(PVOID pAddr, DWORD dwLength, DWORD dwLineLength);
;
; Arguments:
;	r0: pAddr -- virtual address at which to start flushing, on dwLineLength-byte 
;              alignment
;	r1: dwLength -- number of bytes to invalidate, must be > zero.
;        r2: dwLineLength -- number of bytes in a cache line
;
; Return Value:
;	-- none --
; r0..r3 junk
; CC flags junk	
;--

    ; clean & invalidate the range of lines
10

    mcr	p15, 0, r0, c7, c14, 1 ; clean AND invalidate line in proper set and way based on MVA.
                                      
 IF {TRUE}	
	;for L2
	mcr p15, 1, r0, c7, c11, 1 ; clean
	mcr p15, 1, r0, c7, c7, 1 ; invalidate
 ENDIF
                                       
    add     r0, r0, r2          ; on to the next line
    subs    r1, r1, r2          ; reduce the number of bytes left
    bgt     %b10                ; loop while > 0 bytes left
   
    ; set up a data write barrier.
    mcr     p15, 0, r0, c7, c10, 4
    
    RETURN

    LEAF_ENTRY	XScaleFlushDCacheLines
;++
; Routine Description:
;    Clean and invalidate some number of Data Cache lines.
;
; Syntax:
;	void XScaleFlushDCacheLines(PVOID pAddr, DWORD dwLength, DWORD dwLineLength);
;
; Arguments:
;	r0: pAddr -- virtual address at which to start flushing, on dwLineLength-byte 
;              alignment
;	r1: dwLength -- number of bytes to invalidate, must be > zero.
;        r2: dwLineLength -- number of bytes in a cache line
;
; Return Value:
;	-- none --
; r0..r3 junk
; CC flags junk	
;--

    ; clean & invalidate the range of lines
10

    mcr	p15, 0, r0, c7, c14, 1 ; clean AND invalidate line in proper set and way based on MVA.
                                       
    add     r0, r0, r2          ; on to the next line
    subs    r1, r1, r2          ; reduce the number of bytes left
    bgt     %b10                ; loop while > 0 bytes left
   
    ; set up a data write barrier.
    mcr     p15, 0, r0, c7, c10, 4
    
    RETURN


    END

